<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Zend_Service_WindowsAzure_Storage_Blob - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.service.windowsazure.storage.blob.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.service.windowsazure.storage.blob.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.service.windowsazure.storage.blob" class="section"><div class="info"><h1 class="title">Zend_Service_WindowsAzure_Storage_Blob</h1></div>
    

    <p class="para">
        Blob Storage stores sets of binary data. Blob storage offers the following three
        resources: the storage account, containers, and blobs.  Within your storage account,
        containers provide a way to organize sets of blobs within your storage account.
    </p>

    <p class="para">
        Blob Storage is offered by Windows Azure as a <acronym class="acronym">REST</acronym> <acronym class="acronym">API</acronym>
        which is wrapped by the <span class="classname">Zend_Service_WindowsAzure_Storage_Blob</span> class
        in order to provide a native <acronym class="acronym">PHP</acronym> interface to the storage account.
    </p>

    <div class="section" id="zend.service.windowsazure.storage.blob.api"><div class="info"><h1 class="title">API Examples</h1></div>
        

        <p class="para">
            This topic lists some examples of using the
            <span class="classname">Zend_Service_WindowsAzure_Storage_Blob</span> class.  Other features are
            available in the download package, as well as a detailed <acronym class="acronym">API</acronym>
            documentation of those features.
        </p>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.create-container"><div class="info"><h1 class="title">Creating a storage container</h1></div>
            

            <p class="para">
                Using the following code, a blob storage container can be created on development
                storage.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.create-container.example"><div class="info"><p><b>Example #1 Creating a storage container</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
$result = $storageClient-&gt;createContainer(&#039;testcontainer&#039;);

echo &#039;Container name is: &#039; . $result-&gt;Name;
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.delete-container"><div class="info"><h1 class="title">Deleting a storage container</h1></div>
            

            <p class="para">
                Using the following code, a blob storage container can be removed from development
                storage.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.delete-container.example"><div class="info"><p><b>Example #2 Deleting a storage container</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
$storageClient-&gt;deleteContainer(&#039;testcontainer&#039;);
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.storing-blob"><div class="info"><h1 class="title">Storing a blob</h1></div>
            

            <p class="para">
                Using the following code, a blob can be uploaded to a blob storage container on
                development storage. Note that the container has already been created before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.storing-blob.example"><div class="info"><p><b>Example #3 Storing a blob</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();

// upload /home/maarten/example.txt to Azure
$result = $storageClient-&gt;putBlob(
    &#039;testcontainer&#039;, &#039;example.txt&#039;, &#039;/home/maarten/example.txt&#039;
);

echo &#039;Blob name is: &#039; . $result-&gt;Name;
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.copy-blob"><div class="info"><h1 class="title">Copying a blob</h1></div>
            

            <p class="para">
                Using the following code, a blob can be copied from inside the storage account. The
                advantage of using this method is that the copy operation occurs in the Azure cloud
                and does not involve downloading the blob. Note that the container has already been
                created before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.copy-blob.example"><div class="info"><p><b>Example #4 Copying a blob</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();

// copy example.txt to example2.txt
$result = $storageClient-&gt;copyBlob(
    &#039;testcontainer&#039;, &#039;example.txt&#039;, &#039;testcontainer&#039;, &#039;example2.txt&#039;
);

echo &#039;Copied blob name is: &#039; . $result-&gt;Name;
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.download-blob"><div class="info"><h1 class="title">Downloading a blob</h1></div>
            

            <p class="para">
                Using the following code, a blob can be downloaded from a blob storage container on
                development storage. Note that the container has already been created before and a
                blob has been uploaded.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.download-blob.example"><div class="info"><p><b>Example #5 Downloading a blob</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();

// download file to /home/maarten/example.txt
$storageClient-&gt;getBlob(
    &#039;testcontainer&#039;, &#039;example.txt&#039;, &#039;/home/maarten/example.txt&#039;
);
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.api.public-blob"><div class="info"><h1 class="title">Making a blob publicly available</h1></div>
            

            <p class="para">
                By default, blob storage containers on Windows Azure are protected from public
                viewing. If any user on the Internet should have access to a blob container, its ACL
                can be set to public. Note that this applies to a complete container and not to a
                single blob!
            </p>

            <p class="para">
                Using the following code, blob storage container ACL can be set on development
                storage. Note that the container has already been created before.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.api.public-blob.example"><div class="info"><p><b>Example #6 Making a blob publicly available</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();

// make container publicly available (enumerate all blobs and read blob data)
$storageClient-&gt;setContainerAcl(&#039;testcontainer&#039;, Zend_Service_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
</pre>

            </div>
        </div>
    </div>

    <div class="section" id="zend.service.windowsazure.storage.blob.root"><div class="info"><h1 class="title">Root container</h1></div>
        

        <p class="para">
            Windows Azure Blob Storage provides support to work with a &quot;root container&quot;.
            This means that a blob can be stored in the root of your storage account,
            i.e. <var class="filename">http://myaccount.blob.core.windows.net/somefile.txt</var>.
        </p>

        <p class="para">
            In order to work with the root container, it should first be created using the
             <span class="methodname">createContainer()</span> method, naming the container
            <var class="varname">$root</var>. All other operations on the root container should be issued
            with the container name set to <var class="varname">$root</var>.
        </p>
    </div>

    <div class="section" id="zend.service.windowsazure.storage.blob.wrapper"><div class="info"><h1 class="title">Blob storage stream wrapper</h1></div>
        

        <p class="para">
            The Windows Azure <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym> provides support
            for registering a blob storage client as a <acronym class="acronym">PHP</acronym> file stream wrapper.
            The blob storage stream wrapper provides support for using regular file operations on
            Windows Azure Blob Storage. For example, one can open a file from Windows Azure Blob
            Storage with the  <span class="methodname">fopen()</span> function:
        </p>

        <div class="example" id="zend.service.windowsazure.storage.blob.wrapper.sample"><div class="info"><p><b>Example #7 Example usage of blob storage stream wrapper</b></p></div>
            

            <pre class="programlisting brush: php">
$fileHandle = fopen(&#039;azure://mycontainer/myfile.txt&#039;, &#039;r&#039;);

// ...

fclose($fileHandle);
</pre>

        </div>

        <p class="para">
            In order to do this, the Windows Azure <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym>
            blob storage client must be registered as a stream wrapper. This can be done by calling
            the  <span class="methodname">registerStreamWrapper()</span> method:
        </p>

        <div class="example" id="zend.service.windowsazure.storage.blob.wrapper.register"><div class="info"><p><b>Example #8 Registering the blob storage stream wrapper</b></p></div>
            

            <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob();

// registers azure:// on this storage client
$storageClient-&gt;registerStreamWrapper();

// or:

// regiters blob:// on this storage client
$storageClient-&gt;registerStreamWrapper(&#039;blob://&#039;);
</pre>

        </div>

        <p class="para">
            To unregister the stream wrapper, the  <span class="methodname">unregisterStreamWrapper()</span>
            method can be used.
        </p>
    </div>

    <div class="section" id="zend.service.windowsazure.storage.blob.sharedaccesssig"><div class="info"><h1 class="title">Shared Access Signature</h1></div>
        

        <p class="para">
            Windows Azure Bob Storage provides a feature called &quot;Shared Access Signatures&quot;. By
            default, there is only one level of authorization possible in Windows Azure Blob
            Storage: either a container is private or it is public. Shared Access Signatures provide
            a more granular method of authorization: read, write, delete and list permissions can be
            assigned on a container or a blob and given to a specific client using an URL-based
            model.
        </p>

        <p class="para">
            An example would be the following signature:
        </p>

        <pre class="literallayout">
http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&amp;se=2009-08-17T09%3A56%3A17Z&amp;sr=c&amp;sp=w&amp;sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D
        </pre>

        <p class="para">
            The above signature gives write access to the &quot;phpazuretestshared1&quot;
            container of the &quot;phpstorage&quot; account.
        </p>

        <div class="section" id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate"><div class="info"><h1 class="title">Generating a Shared Access Signature</h1></div>
            

            <p class="para">
                When you are the owner of a Windows Azure Bob Storage account, you can create and
                distribute a shared access key for any type of resource in your account. To do this,
                the  <span class="methodname">generateSharedAccessUrl()</span> method of the
                <span class="classname">Zend_Service_WindowsAzure_Storage_Blob</span> storage client can be
                used.
            </p>

            <p class="para">
                The following example code will generate a Shared Access Signature for write access
                in a container named &quot;container1&quot;, within a timeframe of 3000 seconds.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate-2"><div class="info"><p><b>Example #9 Generating a Shared Access Signature for a container</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient   = new Zend_Service_WindowsAzure_Storage_Blob();
$sharedAccessUrl = $storageClient-&gt;generateSharedAccessUrl(
    &#039;container1&#039;,
    &#039;&#039;,
    &#039;c&#039;,
    &#039;w&#039;,
    $storageClient -&gt;isoDate(time() - 500),
    $storageClient -&gt;isoDate(time() + 3000)
);
</pre>

            </div>

            <p class="para">
                The following example code will generate a Shared Access Signature for read access
                in a blob named <var class="filename">test.txt</var> in a container named &quot;container1&quot;
                within a time frame of 3000 seconds.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.sharedaccesssig-generate-3"><div class="info"><p><b>Example #10 Generating a Shared Access Signature for a blob</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient   = new Zend_Service_WindowsAzure_Storage_Blob();
$sharedAccessUrl = $storageClient-&gt;generateSharedAccessUrl(
    &#039;container1&#039;,
    &#039;test.txt&#039;,
    &#039;b&#039;,
    &#039;r&#039;,
    $storageClient -&gt;isoDate(time() - 500),
    $storageClient -&gt;isoDate(time() + 3000)
);
</pre>

            </div>
        </div>

        <div class="section" id="zend.service.windowsazure.storage.blob.sharedaccesssig.consume"><div class="info"><h1 class="title">Working with Shared Access Signatures from others</h1></div>
            

            <p class="para">
                When you receive a Shared Access Signature from someone else, you can use the
                Windows Azure <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym> to work with the
                addressed resource. For example, the following signature can be retrieved from the
                owner of a storage account:
            </p>

            <pre class="literallayout">
http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&amp;se=2009-08-17T09%3A56%3A17Z&amp;sr=c&amp;sp=w&amp;sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D
            </pre>

            <p class="para">
                The above signature gives write access to the &quot;phpazuretestshared1&quot; &quot;container&quot; of
                the phpstorage account. Since the shared key for the account is not known, the
                Shared Access Signature can be used to work with the authorized resource.
            </p>

            <div class="example" id="zend.service.windowsazure.storage.blob.sharedaccesssig.consuming"><div class="info"><p><b>Example #11 Consuming a Shared Access Signature for a container</b></p></div>
                

                <pre class="programlisting brush: php">
$storageClient = new Zend_Service_WindowsAzure_Storage_Blob(
    &#039;blob.core.windows.net&#039;, &#039;phpstorage&#039;, &#039;&#039;
);
$storageClient-&gt;setCredentials(
    new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature()
);
$storageClient-&gt;getCredentials()-&gt;setPermissionSet(array(
    &#039;http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&amp;se=2009-08-17T09%3A56%3A17Z&amp;sr=c&amp;sp=w&amp;sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D&#039;
));
$storageClient-&gt;putBlob(
    &#039;phpazuretestshared1&#039;, &#039;NewBlob.txt&#039;, &#039;C:\Files\dataforazure.txt&#039;
);
</pre>

            </div>

            <p class="para">
                Note that there was no explicit permission to write to a specific blob. Instead, the
                Windows Azure <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym> determined that a
                permission was required to either write to that specific blob, or to write to its
                container. Since only a signature was available for the latter, the Windows Azure
                <acronym class="acronym">SDK</acronym> for <acronym class="acronym">PHP</acronym> chose those credentials to perform
                the request on Windows Azure blob storage.
            </p>
        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.service.html">Zend_Service</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.service.html">Zend_Service</a></li>
  <li><a href="zend.service.introduction.html">Introdu&ccedil;&atilde;o</a></li>
  <li><a href="zend.service.akismet.html">Zend_Service_Akismet</a></li>
  <li><a href="zend.service.amazon.html">Zend_Service_Amazon</a></li>
  <li><a href="zend.service.amazon.ec2.html">Zend_Service_Amazon_Ec2</a></li>
  <li><a href="zend.service.amazon.ec2.instance.html">Zend_Service_Amazon_Ec2: Instances</a></li>
  <li><a href="zend.service.amazon.ec2.windows.instance.html">Zend_Service_Amazon_Ec2: Windows Instances</a></li>
  <li><a href="zend.service.amazon.ec2.reserved.instance.html">Zend_Service_Amazon_Ec2: Reserved Instances</a></li>
  <li><a href="zend.service.amazon.ec2.cloudwatch.html">Zend_Service_Amazon_Ec2: CloudWatch Monitoring</a></li>
  <li><a href="zend.service.amazon.ec2.images.html">Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)</a></li>
  <li><a href="zend.service.amazon.ec2.ebs.html">Zend_Service_Amazon_Ec2: Elastic Block Storage (EBS)</a></li>
  <li><a href="zend.service.amazon.ec2.elasticip.html">Zend_Service_Amazon_Ec2: Elastic IP Addresses</a></li>
  <li><a href="zend.service.amazon.ec2.keypairs.html">Zend_Service_Amazon_Ec2: Keypairs</a></li>
  <li><a href="zend.service.amazon.ec2.zones.html">Zend_Service_Amazon_Ec2: Regions and Availability Zones</a></li>
  <li><a href="zend.service.amazon.ec2.securitygroups.html">Zend_Service_Amazon_Ec2: Security Groups</a></li>
  <li><a href="zend.service.amazon.s3.html">Zend_Service_Amazon_S3</a></li>
  <li><a href="zend.service.amazon.sqs.html">Zend_Service_Amazon_Sqs</a></li>
  <li><a href="zend.service.audioscrobbler.html">Zend_Service_Audioscrobbler</a></li>
  <li><a href="zend.service.delicious.html">Zend_Service_Delicious</a></li>
  <li><a href="zend.service.developergarden.html">Zend_Service_DeveloperGarden</a></li>
  <li><a href="zend.service.ebay.html">Zend_Service_Ebay</a></li>
  <li><a href="zend.service.ebay.finding.html">Zend_Service_Ebay_Finding</a></li>
  <li><a href="zend.service.flickr.html">Zend_Service_Flickr</a></li>
  <li><a href="zend.service.livedocx.html">Zend_Service_LiveDocx</a></li>
  <li><a href="zend.service.nirvanix.html">Zend_Service_Nirvanix</a></li>
  <li><a href="zend.service.recaptcha.html">Zend_Service_ReCaptcha</a></li>
  <li><a href="zend.service.short-url.html">Zend_Service_ShortUrl</a></li>
  <li><a href="zend.service.simpy.html">Zend_Service_Simpy</a></li>
  <li><a href="zend.service.slideshare.html">Zend_Service_SlideShare</a></li>
  <li><a href="zend.service.strikeiron.html">Zend_Service_StrikeIron</a></li>
  <li><a href="zend.service.strikeiron.bundled-services.html">Zend_Service_StrikeIron: Bundled Services</a></li>
  <li><a href="zend.service.strikeiron.advanced-uses.html">Zend_Service_StrikeIron: Advanced Uses</a></li>
  <li><a href="zend.service.technorati.html">Zend_Service_Technorati</a></li>
  <li><a href="zend.service.twitter.html">Zend_Service_Twitter</a></li>
  <li><a href="zend.service.windowsazure.html">Zend_Service_WindowsAzure</a></li>
  <li class="active"><a href="zend.service.windowsazure.storage.blob.html">Zend_Service_WindowsAzure_Storage_Blob</a></li>
  <li><a href="zend.service.windowsazure.diagnostics.manager.html">Zend_Service_WindowsAzure_Diagnostics_Manager</a></li>
  <li><a href="zend.service.windowsazure.storage.queue.html">Zend_Service_WindowsAzure_Storage_Queue</a></li>
  <li><a href="zend.service.windowsazure.storage.table.html">Zend_Service_WindowsAzure_Storage_Table</a></li>
  <li><a href="zend.service.yahoo.html">Zend_Service_Yahoo</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>